#pragma once
#include "hash_table.h"

namespace Unordered_Set
{
	template<class K, class Hash = HashFunc<K>>
	class unordered_set
	{
	public:
		//仿函数
		struct SetKeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		//迭代器
		typedef typename HashBucket::HashTable<K, K, SetKeyOfT, Hash>::const_iterator iterator;
		typedef typename HashBucket::HashTable<K, K, SetKeyOfT, Hash>::const_iterator const_iterator;

		iterator begin()
		{
			return _ht.begin();
		}

		iterator end()
		{
			return _ht.end();
		}

		const_iterator begin() const
		{
			return _ht.begin();
		}

		const_iterator end() const
		{
			return _ht.end();
		}

		//接口: insert + erase + find
		pair<iterator, bool> insert(const K& key)
		{
			return _ht.Insert(key);
		}

		iterator find(const K& key)
		{
			return _ht.Find(key);
		}

		bool erase(const K& key)
		{
			return _ht.Erase(key);
		}

	private:
		HashBucket::HashTable<K, K, SetKeyOfT, Hash> _ht;
	};

	void test1() 
	{
		unordered_set<int> s1;
		s1.insert(1);
		s1.insert(11);
		s1.insert(2);
		s1.insert(3);
		s1.insert(4);

		for (auto& num : s1) 
		{
			cout << num << " ";
		}
		cout << endl;
	}

	void test2()
	{
		unordered_set<int> s1;
		s1.insert(1);
		s1.insert(11);
		s1.insert(2);
		s1.insert(3);
		s1.insert(4);
		auto it = s1.begin();
		while (it != s1.end()) 
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}
}